package com.yuke.cloud.service.wmc.service.impl;

import com.yuke.cloud.common.core.support.BaseService;
import com.yuke.cloud.service.wmc.dao.DicRegionMapper;
import com.yuke.cloud.service.wmc.entity.DicRegion;
import com.yuke.cloud.service.wmc.service.DicRegionService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;


/**
 * Created by wg on 2018/11/22.
 */
@Service
@Transactional
public class DicRegionServiceImpl extends BaseService<DicRegion> implements DicRegionService {
    @Resource
    private DicRegionMapper dicRegionMapper;

    @Override
    public List<Map> selectbyreginid(Long id) {
        List<Map> list = dicRegionMapper.selectbyreginid(id);
        return list;
    }

    @Override
    public List<String> finprovince(List<String> list) {
        List<String> list1 = new ArrayList<>();
        for (int i = 0; i < list.size(); i++) {
            List<Long> list4 = new ArrayList<>();
            String[] split = list.get(i).split(",");
            for (int j = 0; j < split.length; j++) {
                list4.add(Long.valueOf(split[j]));
            }
            StringBuilder sb = new StringBuilder();
            List<Map> list2 = dicRegionMapper.finprovince(list4);
            for (int j = 0; j < list2.size(); j++) {
                if (j != list2.size()-1) {
                    sb.append(list2.get(j).get("region_name")).append(",");
                } else {
                    sb.append(list2.get(j).get("region_name"));
                }
            }
            list1.add(sb.toString());
        }
        return list1;
    }

    @Override
    public List<Map> getallprovince() {
        return dicRegionMapper.getallprovince();
    }
}
